//index.js
var network = require("../../api/api.js")
//获取应用实例
const app = getApp()
Page({
    data: {
      movies: [
      ],
        resource: [],
      img:"../../images/3i.png",
      title:"学习资料",
      intro:"是关于口腔学习的，照着开发文档尝试,总是能有所收获.之前做Android开发,做个轮播图并不简单,用上viewpage再设置圆点,折腾一通之后还一堆bug.今天尝试微信小程序开发做轮播图,真是感动的泪流满面.废话说完了,上图.",
      imgin: "../../images/4i.jpg",
      imginnn:"../../images/10.png",
      motto: 'Hello World',
     userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
    },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
    toNaticeDetail: function (e) {
        const href = e.currentTarget.dataset.href
        wx.navigateTo({
            url: '../detail/detail?href=' + href
        })
    },
    toResourceDetail: function (e) {
        const query = JSON.stringify(e.currentTarget.dataset.query || {})
        let query1 = e.currentTarget.dataset.query || {};
        //存储到本地 resource_id 唯一值
        wx.setStorage({
          key: "resource_id_" + query1.resource_id,
          data: query1.vedio_path
        })
        query1.vedio_path ="";
        query1 = JSON.stringify(query1 || {});
        wx.navigateTo({
          url: '../video/video?query=' + query1
        })
    },
    pageInit: function (bool) {
      var userLogin = wx.getStorageSync('user_login') || {}
        this.getNoticeList()
        this.getResourceList()
        // var userLogin = wx.getStorageSync('user_login') || {}
        // if (userLogin.prompt_read_status === 1) {
        //     wx.navigateTo({
        //         url: '../learning/learning'
        //     })
        // } else {
        //     this.getNoticeList()
        //     this.getResourceList()
        // }
    },
  onLoad: function () {
        this.pageInit(true)
  },
    onShow: function () {
        this.pageInit()
    },
  getNoticeList: function () {
      var that = this
      var params = new Object()
      network.POST(
          {
              params: params,
              url: "find_notice_list",
              success: function (res) {
                  that.setData({movies: res.result })
              },
              fail: function () {
                  //失败后的逻辑

              },
          })
  },
    getResourceList: function () {
        var that = this
        var userLogin = wx.getStorageSync('user_login') || {}
        var params = new Object()
        network.POST(
            {
                params: params,
                url: "get_resource_list",
                success: function (res) {
                    that.setData({resource: res.result })
                },
                fail: function () {
                    //失败后的逻辑

                },
            })
    }
})
